package graph.drawingshapes.shapes
{
	import graph.drawingshapes.BaseFill;
	import graph.drawingshapes.NoFill;
	import graph.drawingshapes.RedrawEvent;
	
	import mx.events.PropertyChangeEvent;
	
	public class FilledDrawingShape extends DrawingShape
	{
		[Bindable]
		private var _fill:BaseFill = new NoFill();
		[Bindable]
		public function get fill():BaseFill
		{
			return this._fill;
		}
		public function set fill(value:BaseFill):void
		{
			this._fill = value;
			this._fill.addEventListener(RedrawEvent.REDRAW, onRedrawEvent);
			this._fill.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, onProperyChangeEvent);
			dispatchEvent(new RedrawEvent());
		}
		
		public function FilledDrawingShape(x:Number=DefaultX, y:Number=DefaultY)
		{
			super(x,y);
		}
		
		protected override function initHandlers():void
		{
			super.initHandlers();
			this.fill.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, onProperyChangeEvent);
			this.fill.addEventListener(RedrawEvent.REDRAW, onRedrawEvent);
		}
		
		protected override function initDrawing():void
		{
			super.initDrawing();
			fill.beginFill(this.graphics);
		}
		
		protected override function endDrawing():void
		{
			super.endDrawing();
			fill.endFill(this.graphics);
		}
	}
}